package com.yz.ssm.controller;

import com.yz.ssm.mapper.UserMapper;
import com.yz.ssm.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by apple on 2017/8/27.
 */
@Controller
public class UserController {
    @RequestMapping("/")
    @ResponseBody
    public String hello(){
        return "hello";
    }

    @RequestMapping("/hello/{name}")
    public String user(@PathVariable String name,Model model){
        model.addAttribute("name",name);
        return "user";
    }

    @Autowired
    private UserMapper userMapper;
    @RequestMapping("/user/{id}")
    @ResponseBody
    public User user(@PathVariable Integer id){
        return userMapper.findUserById(id);
    }
}
